<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>组件写法</title>
</head>
<body>
<script src="../js/react.min.js"></script>
<script src="../js/react-dom.min.js"></script>
<script src="../js/JSXTransformer.js"></script>
<script type="text/jsx">
  "use strict"

  // 组件通信
  const GenderSelect = React.createClass({
    render() {
      // props 调用父组件的方法
      return <select onChange={this.props.handleSelect}>
        <option value="0">男</option>
        <option value="1">女</option>
      </select>
    }
  })

  const SignupForm = React.createClass({
    getInitialState() {
      return {
        name: '',
        password: '',
        gender: '0'
      }
    },
    handleChange(name, event) {
      this.setState({ [name]: event.target.value })
    },
    handleSelect(event) {
      this.setState({ gender: event.target.value })
    },
    render() {
      console.log(this.state);
      return <form>
        <input type="text" placeholder="请输入用户名称" onChange={this.handleChange.bind(this, 'name')}/>
        <input type="password" placeholder="请输入用户密码" onChange={this.handleChange.bind(this, 'password')}/>
        <GenderSelect handleSelect={this.handleSelect}/>
      </form>
    }
  })

  ReactDOM.render(<SignupForm/>, document.body)

</script>
</body>
</html>